package com.example.demo.design_pattern.template;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author xkx
 * @description 模板模式
 */
public abstract class AbstractTravelTemplate {

  private final Logger log = LoggerFactory.getLogger(this.getClass());

  protected boolean needPrepare = true;

  /**
   * 具体的整个过程
   */
  public final void doTravel() {
    if (needPrepare) {
      log.info("需要准备");
      this.preparation();
    } else {
      log.info("不需要准备");
    }
    this.doing();
    this.backHome();
  }

  /**
   * 是否需要准备(钩子方法)
   *
   * @param needPrepare 是否需要进行准备
   */
  protected void setNeedPrepare(boolean needPrepare) {
    this.needPrepare = needPrepare;
  }

  /**
   * 准备
   */
  protected abstract void preparation();

  /**
   * 骑行
   */
  protected abstract void doing();

  /**
   * 返程
   */
  protected abstract void backHome();
}